<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>短信发送量统计分析</title>
    <link href="../../layui/css/layui.css" rel="stylesheet" type="text/css">
    <link href="../../css/style.css" rel="stylesheet" type="text/css">
    <script src="../../layui/layui.js"></script>
    <script src="../../js/jquery-1.8.3.js"></script>
    <script src="../../js/util.js"></script>
    <script>
        layui.use(['laypage', 'layer', 'table', 'form', 'jquery', 'laydate', 'element'], function () {
            var table = layui.table;
            var laypage = layui.laypage;
            var layer = layui.layer;
            var form = layui.form;
            var $ = layui.$;
            var laydate = layui.laydate;
            var tableData = {
                elem: '#table',
                id: "modelReload", //id
                url: '/smsReportTotal/find?countWay=county',
                method: 'post',
                request: {
                    pageName: 'page',
                    limitName: 'limit'
                },
                response: {
                    statusName: 'code',
                    statusCode: 0,
                    msgName: 'msg',
                    countName: 'count',
                    dataName: 'data'
                }
                , limit: 10,
                limits: [10, 20, 30, 40, 50],
                layout: ['prev', 'page', 'next'],
                prev: "上一页",
                next: "下一页",
                page: true //开启分页
                , cols: [[
                    {
                        field: 'cityName', title: '地市', rowspan: 2
                    }
                    ,{
                        field: 'countyName', title: '区县', rowspan: 2
                    }
                    , {title: '长短信', colspan: 3, align: 'center'}
                    , {title: '正常短信', sort: true, colspan: 2, align: 'center'}
                    , {title: '外来用户', colspan: 2, align: 'center'}], [
                      {field: 'longNum', title: '发送量'}
                    , {field: 'longNumSplit', title: '长短信拆分后数量'}
                    , {field: 'longPercent', title: '占比'}
                    , {field: 'normalNum', title: '发送量'}
                    , {field: 'normalPercent', title: '占比'}
                    , {field: 'fieldNum', title: '发送量'}//,event: 'setSign', style: 'cursor: pointer;'}
                    , {field: 'fieldPercent', title: '占比'}
                ]]
            };
            //监听项目  区县
            form.on('select(cityId)', function (data) {
            	var data2 = selectCountyId(data.value);
                appendCounty(data2);
                //var data = selectMgrInfo(data.value);
                //appendMgr(data);
            });
            //监听项目
            /* form.on('select(countyId)', function (data) {
                var data1 = selectMgrInfo(data.value);
                appendMgr(data1);
            }); */
            //根据城市ID查询区县
            function selectCountyId(cityId) {
                var data;
                var url = '/util/findCountyByCityId?cityId=' + cityId;
                $.ajax({
                        type: 'post',
                        async: false,
                        url: url,
                        success: function (json) {
                            data = json.data;
                        }, error: function () {
                            layer.msg('系统异常，请联系管理员处理!');
                        }
                    }
                );
                return data;
            }
            //根据城市ID查询项目
            function selectMgrInfo(cityId) {
                var data;
                var url = '/util/findByMgrId?countyId=' + cityId;
                $.ajax({
                        type: 'post',
                        async: false,
                        url: url,
                        success: function (json) {
                            data = json.data;
                        }, error: function () {
                            layer.msg('系统异常，请联系管理员处理!');
                        }
                    }
                );
                return data;
            }
            //动态拼接区县
            function appendCounty(data){
                if (data.length != null) {
                    var options = '<option value="">请先选择地市</option>';
                    for (var i = 0; i < data.length; i++) {
                        options += '<option value="' + data[i].countyId + '">' + data[i].countyName + '</option>';
                    }
                    $('#countyId').html(options);
                } else {
                    $('#countyId').html('该地市下没有区县');
                }
                form.render();
            }
            $('#query').on('click', function () {
                //身份识别
                $.ajax({
                    type: 'post',
                    async: false,
                    url: '/util/findUser',
                    success: function (json) {

                        if (json.duty == 2) {
                            layer.msg("对不起，您的权限不足，请选择其他的统计方式")
                        } else {
                            var startTime = $("#startTime").val();
                            var endTime = $("#endTime").val();
                            var way = $("input[name='way']:checked").val();
                            var countyId = $("#countyId").val();
                            if (judetmentDate(startTime, endTime) && way == 1) {
                                layer.msg("您选择的时间超出了30天，请重新选择");
                            } else if(countyId==null || countyId == ''){
                            	layer.msg("您需要选择查询的区县，请重新选择");
                            } else {
                                var index = layer.load(1, {
                                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                                });
                                table.reload('modelReload', {
                                    method: 'post',
                                    page: {
                                        curr: 1
                                    },
                                    where: {
                                        way: way,
                                        startTime: formatDate(startTime),
                                        endTime: formatDate(endTime),
                                        month: $("#yearmonth").val(),
                                        cityId: $("#cityId").val(),
                                        countyId: $("#countyId").val()
                                    }
                                });
                                layer.close(index);
                            }
                        }
                    }, error: function () {
                        layer.msg('系统异常，请联系管理员处理!');
                    }
                });

            });

            //身份识别
            $(document).ready(function () {
                $.ajax({
                    type: 'post',
                    async: false,
                    url: '/util/findUser',
                    success: function (json) {
                    if (json.duty == 2) {
                           $("#city").remove();
                        }
                    }, error: function () {
                        layer.msg('系统异常，请联系管理员处理!');
                    }
                });
            });
            //导出
            $('#download').on('click', function () {
                //身份识别
                $.ajax({
                    type: 'post',
                    async: false,
                    url: '/util/findUser',
                    success: function (json) {
                        var startTime = $("#startTime").val();
                        var endTime = $("#endTime").val();
                        var way = $("input[name='way']:checked").val();
                        if (judetmentDate(startTime, endTime) && way == 1) {
                            layer.msg("您选择的时间超出了30天，请重新选择");
                        } else {
                            var url = "/smsReportTotal/download?countWay=county"
                                + "&way=" + way
                                + "&startTime=" + formatDate(startTime)
                                + "&endTime=" + formatDate(endTime)
                                + "&month=" + $("#yearmonth").val()
                                + "&countyId=" + $("#countyId").val();
                            location.href = url;
                        }
                    }
                });
            });
            //时间下拉框设置
            //时间选择器的样式
            //获取系统时间，做时间选择
            //获取指定月的天数
            var myDate = new Date();
            //获取当前的年份
            var year = myDate.getFullYear();
            //获取当前月的月份

            var month = myDate.getMonth() + 1;
            //上一月的年份
            var inityear = (month - 1 > 0 ? year : year - 1);
            //上个月的月份
            var initmonth = (month - 1 > 0 ? month - 1 : 12);

            initmonth = (initmonth < 10 ? 0 + "" + initmonth : initmonth);

            //初始化最大月份
            var maxdate = inityear + '-' + initmonth + '-' + 25;

            //前6个月的月份
            var minmonth = month - 6;

            //前6个月的年份
            var minyear = (minmonth > 0 ? year : year - 1);

            minmonth = (minmonth > 0 ? minmonth : minmonth + 12);

            //初始化最小月份
            var mindate = minyear + '-' + minmonth + '-' + 01;

            var maxtime = inityear + '-' + initmonth + "-" + laydate.getEndDate(initmonth, inityear);
            var mintime = minyear + '-' + minmonth + "-01";

            var initiaSartTime = inityear + "-" + initmonth + "-" + '01';
            var initiaEndTime = inityear + "-" + initmonth + "-" + laydate.getEndDate(initmonth, inityear);

            var init = inityear + "" + initmonth;
            laydate.render({
                elem: '#yearmonth'
                , type: 'month'
                , btns: ['clear', 'confirm']
                , trigger: 'click'
                , format: 'yyyyMM'
                , value: init
                , max: maxdate
                , min: mindate
            });
            laydate.render({
                elem: '#startTime'
                , type: 'date'
                , btns: ['clear', 'confirm']
                , trigger: 'click'
                , value: initiaSartTime
                , max: maxtime
                , min: mintime
            });
            laydate.render({
                elem: '#endTime'
                , type: 'date'
                , max: maxtime
                , trigger: 'click'
                , btns: ['clear', 'confirm']
                , value: initiaEndTime
                , max: maxtime
                , min: mintime
            });
            table.render(tableData);

            table.on('tool(demoEvent)', function (obj) {
                var data = obj.data;
                if (obj.event === 'setSign') {
                    layer.open({
                        type: 2,
                        title: '外地人口发送统计',
                        shadeClose: true,
                        shade: false,
                        area: ['800px', '500px']
                        , content: ['fieldCount.html?cityId=' + data.cityId
                        + "&way=" + $("input[name='way']:checked").val()
                        + "&month=" + $("#yearmonth").val()
                        + "&startTime=" + formatDate($("#startTime").val())
                        + "&endTime=" + formatDate($("#endTime").val()),
                            'no']
                    });
                }
            });
        });
    </script>
</head>
<body>
<!--nav-->
<div class="layui-html-limit">
    <!--container-->
    <div class="layui-content-body">
        <div class="scroll-box">
            <div class="breadcrumb-box">
              <span class="layui-breadcrumb" lay-separator="|">
   <a href="javascript:returnIndex2()">首页&nbsp;</a>
  <a href="">&nbsp;报表管理&nbsp;</a>
  <a href="">&nbsp;短信发送量统计分析&nbsp;</a>
  <a href="">&nbsp;按区县统计分析&nbsp;</a>
</span>
            </div>
            <div class="content-box ">
                <div class="form-select-box">
                    <form class="layui-form layui-form-pane" action="">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">省份</label>
                                <div class="layui-input-block">
                                    <input type="text" name="province" lay-verify="required" value="江苏"
                                           autocomplete="off" class="layui-input" disabled>
                                </div>
                            </div>
                            <div class="layui-inline" pane="">
                                <label class="layui-form-label">按统计方式</label>
                                <div class="layui-input-block">
                                    <a href="/view/reportManage/countByCity.html" id="city"><input type="radio" name="countWay" title="按地市"
                                                                                ></a>
                                    <a href="/view/reportManage/countByCounty.html" id="county"><input type="radio" name="countWay" title="按区县"
                                                                                checked=""></a>                                            
                                    <a href="/view/reportManage/countByMgr.html" id="mgr"><input type="radio" name="countWay" title="按项目"></a>
                                    <a href="/view/reportManage/countByRegion.html" id="region"><input type="radio" name="countWay"
                                                                                    title="按区域"></a>
                                    <a href="/view/reportManage/countByStation.html" id="station"><input type="radio" name="countWay"
                                                                                      title="按基站"></a>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                        	<div class="layui-inline">
                                <label class="layui-form-label">地市</label>
                                <div class="layui-input-block">
                                    <select name="cityId" lay-filter="cityId" id="cityId">
                                        <option value="">请选择</option>
                                        <option value="11">苏州</option>
                                        <option value="12">淮安</option>
                                        <option value="13">宿迁</option>
                                        <option value="14">南京</option>
                                        <option value="15">连云港</option>
                                        <option value="16">徐州</option>
                                        <option value="17">常州</option>
                                        <option value="18">镇江</option>
                                        <option value="19">无锡</option>
                                        <option value="20">南通</option>
                                        <option value="21">泰州</option>
                                        <option value="22">盐城</option>
                                        <option value="23">扬州</option>
                                        <option value="25">省级</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
		                            <label class="layui-form-label">区县</label>
		                            <div class="layui-input-block">
		                                <select name="countyId" lay-filter="countyId" id="countyId">
		                                    <option value="">全部</option>
		                                </select>
		                            </div>
		                	</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">发送时间</label>
                            <div class="layui-inline">
                                <div class="layui-inline">
                                    <div class="layui-inline">
                                        <input type="radio" name="way" value="0" title="按月" checked="">
                                    </div>
                                    <div class="layui-inline">
                                        <input type="text" id="yearmonth" placeholder="请选择月份" class="layui-input"
                                               style="width: 100px;" readonly>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <div class="layui-inline">
                                            <input type="radio" name="way" value="1" title="按时间段">
                                        </div>
                                        <div class="layui-inline">
                                            <div class="layui-input-inline" style="width: 130px;">
                                                <input type="text" name="date" id="startTime" autocomplete="off"
                                                       class="layui-input" readonly>
                                            </div>
                                            <div class="layui-form-mid">-</div>
                                            <div class="layui-input-inline" style="width: 130px;">
                                                <input type="text" name="date" id="endTime" autocomplete="off"
                                                       class="layui-input" readonly>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <button class="layui-btn layui-btn-normal" type="button" id="query">
                                            查询
                                        </button>
                                        <button class="layui-btn layui-btn-normal" type="button" id="download">
                                            导出
                                        </button>
                                    </div>
                                    <div style="color: red">短信汇总统计数据只保存6个月，查询时间段不可超出30天，当前月份的时间无法查询</div>
                                </div>
                            </div>
                        </div>

                    </form>
                </div>
                <!--表格-->
                <div class="table-box">
                    <table class="layui-hide" id="table" lay-filter="demoEvent">
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>